package com.ruoyi.stream.server.handler;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.stream.framework.constans.StreamProtocolConstants;
import com.ruoyi.stream.framework.core.protocol.StreamAliveRequest;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class SKARequestEncoder extends MessageToByteEncoder<StreamAliveRequest> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, StreamAliveRequest streamAliveRequest, ByteBuf byteBuf) throws Exception {
        byteBuf.writeBytes(StreamProtocolConstants.SKA_REQ_MAGIC);
        byte[] bytes = JSON.toJSONBytes(streamAliveRequest);
        byteBuf.writeLong(bytes.length);
        byteBuf.writeBytes(bytes);
    }
}
